package com.kmproject.haifu.mvp.ui.adapter;

import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.http.imageloader.glide.ImageConfigImpl;
import com.jess.arms.utils.ArmsUtils;
import com.kmproject.haifu.R;
import com.kmproject.haifu.mvp.model.entity.beans.SecondHandInfoBean;
import com.kmproject.haifu.mvp.ui.widget.RoundCornerImageView;

import java.util.List;

public class SecondHandImgAdapter extends BaseQuickAdapter<SecondHandInfoBean.ImagesBean, BaseViewHolder> {
    ImageLoader glideImage;
    public SecondHandImgAdapter(@Nullable List<SecondHandInfoBean.ImagesBean> data) {
        super(R.layout.secondhand_show_img_item, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SecondHandInfoBean.ImagesBean item) {
        if (glideImage == null) {
            glideImage = ArmsUtils.obtainAppComponentFromContext(mContext).imageLoader();
        }
        helper.<RoundCornerImageView>getView(R.id.secondhand_show_img_item_RoundCornerImageView).setmBorderRadius(10);
        if (getItemCount()==1)
        {
            //只有一张
            helper.<RoundCornerImageView>getView(R.id.secondhand_show_img_item_RoundCornerImageView).setmCornerType(RoundCornerImageView.CornerType.ALL);
        }else {
            if (helper.getPosition()==0)
            {
                //设置顶部圆角
                helper.<RoundCornerImageView>getView(R.id.secondhand_show_img_item_RoundCornerImageView).setmCornerType(RoundCornerImageView.CornerType.TOP);
            }
            if (helper.getPosition()==getItemCount()-1)
            {
                //设置底部圆角
                helper.<RoundCornerImageView>getView(R.id.secondhand_show_img_item_RoundCornerImageView).setmCornerType(RoundCornerImageView.CornerType.BOTTOM);

            }
        }
        glideImage.loadImage(mContext, ImageConfigImpl.builder().url(item.getImageUrl())
                .imageView(helper.<RoundCornerImageView>getView(R.id.secondhand_show_img_item_RoundCornerImageView))
                .build());
    }
}
